package com.ahtg.minispring.starter;

import com.ahtg.minispring.beans.BeanFactory;
import com.ahtg.minispring.core.ClassScanner;
import com.ahtg.minispring.web.handler.HandlerManager;
import com.ahtg.minispring.web.server.TomcatServer;
import java.util.List;

/**
 * 框架入口类
 * @author xiejialin
 * @date 2020/2/20 5:51 PM
 */
public class MiniApplication {

    /**
     *
     * @param clazz 应用入口类，定位到根目录，获取类信息
     * @param args 启动参数数组
     */
    public static void run(Class<?> clazz,String[] args) {
            TomcatServer tomcatServer = new TomcatServer(args);
            try {
                //启动服务
                tomcatServer.startServer();
                //扫描类
                List<Class<?>> classList = ClassScanner.scanClasses(clazz.getPackage().getName());
                //创建bean
                BeanFactory.initBean(classList);
                //映射handler
                HandlerManager.resolveMappingHandler(classList);

                System.out.println("class scan:");
                for(Class<?> c : classList) {
                    System.out.println(c.getName());
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

    }
}
